Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adds feature metrics for collection prefs and button group #3180

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

pan-kot
Copy link
Member

@pan-kot pan-kot commented Jan 10, 2025

Description

Related links, issue #, if available: n/a

How has this been tested?

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pan-kot pan-kot requested a review from a team as a code owner January 10, 2025 11:00
@pan-kot pan-kot requested review from just-boris and removed request for a team January 10, 2025 11:00
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.42%. Comparing base (f9aeff8) to head (9ba4505).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3180    +/-   ##
========================================
  Coverage   96.41%   96.42%            
========================================
  Files         784      784            
  Lines       22168    22179    +11     
  Branches     7206     7610   +404     
========================================
+ Hits        21373    21385    +12     
+ Misses        788      787     -1     
  Partials        7        7            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

expect(useBaseComponent).toHaveBeenCalledWith('ButtonGroup', {
props: {
variant: 'icon',
dropdownExpandToViewport: undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be false instead? Not sure how the metrics handle undefined values here

Copy link
Member

@just-boris just-boris Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics use JSON.stringify. When you serialise undefined, it disappears completely, same as this key did not exist before.

Explicit casting is recommended

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about that too, but decided not touch it just yet. I think it would be nice to align within the team if we want to cast or not and how do we want to treat properties that have defaults: should we pass the default value or the missing one, as it directly affects the actual metrics we gather.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all other cases, we track resolved values after defaulting.

For dropdownExpandToViewport there is an implicit default false which we should be tracking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the team discussion we settled on passing the default property values to metrics. I added a new commit that implements that for dropdownExpandToViewport.

just-boris
just-boris previously approved these changes Jan 13, 2025
Copy link
Member

@just-boris just-boris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment thread is about existing behavior, not new.

Approving, but fixing that reporting would be nice follow up

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
warnOnce: jest.fn(),
}));

afterEach(() => {
(warnOnce as jest.Mock).mockReset();
(useBaseComponent as jest.Mock).mockReset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocking React hooks is an anti pattern, it caused problems in the past, and we do not recommend any teams to do, so we also should not do it in our code.

If you want to test this, do it differently, not via mocking the hook

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it with a spy instead so that the original hook is called.

Copy link
Member

@just-boris just-boris Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original hook is not called.

Try adding a logging around this line, but it is never printed in your test

Copy link
Member Author

@pan-kot pan-kot Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, indeed - apologies! I forgot to remove the old mock after my testing: 9ba4505

I did test it by adding the logs to the original hook, so now it is certainly called for each test case.

@pan-kot pan-kot disabled auto-merge January 15, 2025 12:50
@pan-kot pan-kot added this pull request to the merge queue Jan 16, 2025
Merged via the queue into main with commit 87bff14 Jan 16, 2025
38 checks passed
@pan-kot pan-kot deleted the chore-add-feature-metrics branch January 16, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants